/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-06-08 17:47:02
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-06-08 17:47:17
 * @FilePath: \algorithm-training\leetcode\53. 最大子数组和.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ans = 0;
        vector<int>dp(nums.size());
        dp[0] = nums[0];
        ans = nums[0];
        for(int i = 1; i < nums.size(); i ++)
        {
            dp[i] = max(dp[i - 1] + nums[i],nums[i]);
            ans = max(dp[i],ans);
        }
        return ans;
    }
};